//
//  LXMusicPlayerListVC.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 16/1/4.
//  Copyright © 2016年 蓝鸥科技. All rights reserved.
//

#import "LXMusicPlayerListVC.h"

@interface LXMusicPlayerListVC ()
@property(nonatomic,strong)NSMutableArray *imageArray;
@property(nonatomic,strong)UIImageView *gifImage;
@property(nonatomic,strong)UILabel *label;
@end

@implementation LXMusicPlayerListVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@"%ld",self.musicListArray.count);
    self.imageArray = [NSMutableArray array];
    self.label = [[UILabel alloc]init];
    self.gifImage = [[UIImageView alloc]init];
    [self createNavigation];
    [self createTableView];
}
-(void)createTableView{
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}
-(void)createNavigation{
    self.navigationItem.title = @"播放列表";
    UIImage *back = [UIImage imageNamed:@"icon_back_h@2x.png"];
    back = [back imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:back style:UIBarButtonItemStyleDone target:self action:@selector(leftAction)];
}
-(void)leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.musicListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    if (indexPath.row == self.index) {
    for (int i = 1; i < 19; i++) {
        NSString *name = [NSString stringWithFormat:@"sound_playingbtn%d.tiff",i];
        UIImage *image = [UIImage imageNamed:name];
        [self.imageArray addObject:image];
    }
    self.gifImage.frame = CGRectMake(15, 10, 20, 20);
    self.gifImage.animationImages = self.imageArray;
    self.gifImage.animationDuration = 3;
    self.gifImage.animationRepeatCount = 0;
    [self.gifImage startAnimating];
    self.label.text = [[self.musicListArray objectAtIndex:indexPath.row] title];
    self.label.frame = CGRectMake(self.gifImage.frame.origin.x + self.gifImage.frame.size.width+15, 10, SCREEN_WIDTH - 80, 30);
    [cell addSubview:self.label];
    [cell addSubview:self.gifImage];
    }else{
        cell.imageView.image = [UIImage imageNamed:@"sound_playbtn@2x.png"];
        cell.textLabel.text = [[self.musicListArray objectAtIndex:indexPath.row] title];
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    [self.navigationController popViewControllerAnimated:YES];
}
@end
